layui.use(['table', 'admin', 'ax', 'element','form'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var element = layui.element;
    var form = layui.form;

    //tab切换
    element.on('tab(doTabBrief)', function (data) {
        // console.log(data.index)
    });

    /**
     * 承运商运费信息表管理
     */
    var TransportCarrierFreight = {
        tableId: "transportCarrierFreightTable"
    };

    /**
     * 初始化表格的列
     */
    TransportCarrierFreight.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键id'},
            {align: 'center', toolbar: '#tableBar', title: '操作', width: 140},
            {field: 'recStatus', sort: true, title: '流程状态', templet: '#recStateTpl'},
            {field: 'operateName', sort: true, title: '项目名称'},
            {field: 'startDate', sort: true, title: '发车日期'},
            {field: 'dispatchNumber', sort: true, title: '运输单号', templet: '#dispatchNumberTpl', width: 180},
            {field: 'carrierName', sort: true, title: '承运商名称'},
            {field: 'carnumber', sort: true, title: '车牌号'},
            {field: 'driver1', sort: true, title: '司机名称'},
            {field: 'tel1', sort: true, title: '司机联系方式'},
            {field: 'privatecarType', sort: true, title: '车辆类型'},
            {field: 'mileageTraveled', sort: true, title: '行驶里程'},
            {field: 'totalVolume', sort: true, title: '总体积'},
            {field: 'totalPieces', sort: true, title: '总件数'},
            {field: 'pieceNumberSum', sort: true, title: '整件拆零和'},
            {field: 'freightMoney', sort: true, title: '总运费'},
            {field: 'consultMoney', sort: true, title: '参考运费'},
            {field: 'loadingMoney', sort: true, title: '装车费'},
            {field: 'unloadingMoney', sort: true, title: '卸车费'},
            {field: 'notes', sort: true, title: '备注原因'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    TransportCarrierFreight.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        queryData['operateId'] = $("#operateId").val();
        queryData['carrierId'] = $("#carrierId").val();

        table.reload(TransportCarrierFreight.tableId, {
            where: queryData, page: {curr: 1},
            done: function () {
                // 搜索按钮点击事件
                $('#btnSearch').click(function () {
                    TransportCarrierFreight.search();
                });
                // 添加按钮点击事件
                $('#btnAdd').click(function () {
                    TransportCarrierFreight.openAddDlg();
                });
                // 导出excel
                $('#btnExp').click(function () {
                    TransportCarrierFreight.exportExcel();
                });
            }
        });
    };

    form.on('select(operateId)',function(){
        $("#carrierId").empty();
        $.ajax({
            url:Feng.ctxPath + '/basicCarrier/Querylist',
            dataType:"json",
            async: false,
            data:{"operateId":$("#operateId").val()},
            type:"post",   //请求方式
            success:function(data){
                if(data.length>0){
                    var str = "<option value=''>选择承运商</option>";
                    $.each(data,function(key,value){
                        str += "<option value='"+value.id+"'>"+value.carrierName+"</option>";
                    });
                    $("#carrierId").html(str);
                }
            }
        });
        form.render('select');
    });

    form.on('select(operateId2)',function(){
        $("#carrierId2").empty();
        $.ajax({
            url:Feng.ctxPath + '/basicCarrier/Querylist',
            dataType:"json",
            async: false,
            data:{"operateId":$("#operateId2").val()},
            type:"post",   //请求方式
            success:function(data){
                if(data.length>0){
                    var str = "<option value=''>选择承运商</option>";
                    $.each(data,function(key,value){
                        str += "<option value='"+value.id+"'>"+value.carrierName+"</option>";
                    });
                    $("#carrierId2").html(str);
                }
            }
        });
        form.render('select');
    });

    form.on('select(operateId3)',function(){
        $("#carrierId3").empty();
        $.ajax({
            url:Feng.ctxPath + '/basicCarrier/Querylist',
            dataType:"json",
            async: false,
            data:{"operateId":$("#operateId3").val()},
            type:"post",   //请求方式
            success:function(data){
                if(data.length>0){
                    var str = "<option value=''>选择承运商</option>";
                    $.each(data,function(key,value){
                        str += "<option value='"+value.id+"'>"+value.carrierName+"</option>";
                    });
                    $("#carrierId3").html(str);
                }
            }
        });
        form.render('select');
    });

    form.on('select(operateId4)',function(){
        $("#carrierId4").empty();
        $.ajax({
            url:Feng.ctxPath + '/basicCarrier/Querylist',
            dataType:"json",
            async: false,
            data:{"operateId":$("#operateId4").val()},
            type:"post",   //请求方式
            success:function(data){
                if(data.length>0){
                    var str = "<option value=''>选择承运商</option>";
                    $.each(data,function(key,value){
                        str += "<option value='"+value.id+"'>"+value.carrierName+"</option>";
                    });
                    $("#carrierId4").html(str);
                }
            }
        });
        form.render('select');
    });

    /**
     * 弹出添加对话框
     */
    TransportCarrierFreight.openAddDlg = function () {
        window.location.href = Feng.ctxPath + '/transportCarrierFreight/add';
    };

    /**
     * 导出excel按钮
     */
    TransportCarrierFreight.exportExcel = function () {
        var checkRows = table.checkStatus(TransportCarrierFreight.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    TransportCarrierFreight.openEditDlg = function (data) {
        window.location.href = Feng.ctxPath + '/transportCarrierFreight/edit?id=' + data.id;
    };

    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据
     */
    TransportCarrierFreight.onDeleteItem = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/transportCarrierFreight/delete", function (data) {
                Feng.success("删除成功!");
                table.reload(TransportCarrierFreight.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", data.id);
            ajax.start();
        };
        Feng.confirm("是否删除?", operation);
    };

    /**
     * 承运商确定
     * @param data
     */
    TransportCarrierFreight.confirm = function (data) {
        // 弹出输入框让用户输入审核意见或备注
        layer.prompt({
            title: '请输入确认意见或备注',
            formType: 2,
            value: '', // 设置默认值为空
            maxlength: 100
        }, function (value, index, elem) {

            var confirmData = {
                id: data.id,
                operateId: data.operateId,
                operateName: data.operateName,
                dispatchNumber: data.dispatchNumber,
                notes: value
            }

            var ajax = new $ax(Feng.ctxPath + "/rec/carrierRecDetail/confirm", function (data) {
                Feng.success("确认成功!");
                table.reload(TransportCarrierFreight.tableId);
            }, function (data) {
                Feng.error("确认失败!" + data.responseJSON.message + "!");
            });

            ajax.setData(confirmData);
            ajax.start();

            layer.close(index);
        })
    };


    /**
     * 财务撤回
     * @param data
     */
    TransportCarrierFreight.retract = function (data) {
        // 弹出输入框让用户输入审核意见或备注
        layer.prompt({
            title: '请输入撤回意见或备注',
            formType: 2,
            value: '', // 设置默认值为空
            maxlength: 100
        }, function (value, index, elem) {

            var confirmData = {
                id: data.id,
                operateId: data.operateId,
                operateName: data.operateName,
                dispatchNumber: data.dispatchNumber,
                notes: value
            }

            var ajax = new $ax(Feng.ctxPath + "/rec/carrierRecDetail/retract", function (data) {
                Feng.success("确认成功!");
                table.reload(TransportCarrierFreight.tableId);
            }, function (data) {
                Feng.error("确认失败!" + data.responseJSON.message + "!");
            });

            ajax.setData(confirmData);
            ajax.start();
            layer.close(index);
        })
    };

    /**
     * 承运商申诉
     * @param data
     */
    TransportCarrierFreight.complaint = function (data) {
        // 弹出输入框让用户输入审核意见或备注
        layer.prompt({
            title: '请输入申诉意见或备注',
            formType: 2,
            value: '', // 设置默认值为空
            maxlength: 100
        }, function (value, index, elem) {

            var confirmData = {
                id: data.id,
                operateId: data.operateId,
                operateName: data.operateName,
                dispatchNumber: data.dispatchNumber,
                notes: value
            }

            var ajax = new $ax(Feng.ctxPath + "/rec/carrierRecDetail/complaint", function (data) {
                Feng.success("确认成功!");
                table.reload(TransportCarrierFreight.tableId);
            }, function (data) {
                Feng.error("确认失败!" + data.responseJSON.message + "!");
            });

            ajax.setData(confirmData);
            ajax.start();
            layer.close(index);
        })
    };

    // 承运商确认
    TransportCarrierFreight.btnConfirm = function () {
        var checkStatus = table.checkStatus(TransportCarrierFreight.tableId);
        data = checkStatus.data;

        if (data.length > 0) {
            var ids = [];
            for (var i = 0; i < data.length; i++) {
                ids.push(data[i].id);
            }
            layer.prompt({
                title: '请输入确认意见或备注',
                formType: 2,
                value: '',
                maxlength: 100
            }, function (value, index, elem) {
                $.ajax({
                    url: Feng.ctxPath + "/rec/carrierRecDetail/btnConfirm?ids=" + ids + "&value=" + value,
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        layer.msg(data.message);
                        table.reload(TransportCarrierFreight.tableId);
                    },
                    error: function (jqXHR, textStatus, errorThrown){
                        console.log(errorThrown);
                        layer.msg(data.message);
                    }
                })
                layer.close(index);
            })
        } else {
            layer.alert('请至少选中一条数据');
        }
    }

    // 财务批量撤回
    TransportCarrierFreight.btnRetract = function () {
        var checkStatus = table.checkStatus(TransportCarrierFreight.tableId);
        data = checkStatus.data;

        if (data.length > 0) {
            var ids = [];
            for (var i = 0; i < data.length; i++) {
                ids.push(data[i].id);
            }
            layer.prompt({
                title: '请输入确认意见或备注',
                formType: 2,
                value: '',
                maxlength: 100
            }, function (value, index, elem) {
                $.ajax({
                    url: Feng.ctxPath + "/rec/carrierRecDetail/btnRetract?ids=" + ids + "&value=" + value,
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        layer.msg(data.message);
                        table.reload(TransportCarrierFreight.tableId);
                    },
                    error: function (jqXHR, textStatus, errorThrown){
                        console.log(errorThrown);
                        layer.msg(data.message);
                    }
                })
                layer.close(index);
            })
        } else {
            layer.alert('请至少选中一条数据');
        }
    }

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + TransportCarrierFreight.tableId,
        url: Feng.ctxPath + '/transportCarrierFreight/list',
        page: true,
        limit: 20,
        height: "full-60",
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        cols: TransportCarrierFreight.initColumn(),
        done: function(res, curr, count) {
            // 设置徽章
            var auditCountElement = $('#auditCount');

            if (count > 0) {
                // 如果有数据，则设置 <span> 标签的内容
                if (auditCountElement.length) {
                    auditCountElement.text(count > 99 ? '99+' : count);
                }
            } else {
                if (auditCountElement.length) {
                    // auditCountElement.text(''); // 清空内容
                    auditCountElement.remove();
                }
            }
        }
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        TransportCarrierFreight.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        TransportCarrierFreight.openAddDlg();
    });

    // 导出excel
    $('#btnExp').click(function () {
        TransportCarrierFreight.exportExcel();
    });

    // 承运商批量确认
    $('#btnConfirm').click(function () {
        TransportCarrierFreight.btnConfirm();
    });

    // 财务批量撤回
    $('#btnRetract').click(function () {
        TransportCarrierFreight.btnRetract();
    });


    // 工具条点击事件
    table.on('tool(' + TransportCarrierFreight.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            // 编辑
            TransportCarrierFreight.openEditDlg(data);
        } else if (layEvent === 'delete') {
            // 删除
            TransportCarrierFreight.onDeleteItem(data);
        } else if (layEvent === 'confirm') {
            // 承运商确定
            TransportCarrierFreight.confirm(data);
        } else if (layEvent === 'retract') {
            // 财务撤回
            TransportCarrierFreight.retract(data);
        } else if (layEvent === 'complaint') {
            // 承运商申述
            TransportCarrierFreight.complaint(data);
        } else if (layEvent === 'tooTimeLine') {
            layer.open({
                type: 2,
                title: '时序图',
                area: ['550px', '570px'],
                anim: 5,
                content: Feng.ctxPath + '/rec/carrierRecDetail/tooTimeLine?dispatchNumber=' + data.dispatchNumber,
            });
        }
    });


    /**
     * 承运商运费信息表管理
     */
    var transportConfirm = {
        tableId: "transportConfirm"
    };

    /**
     * 初始化表格的列
     */
    transportConfirm.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键id'},
            {align: 'center', toolbar: '#tableBar2', title: '操作', width: 140},
            {field: 'recStatus', sort: true, title: '流程状态', templet: '#recStateTpl'},
            {field: 'operateName', sort: true, title: '项目名称'},
            {field: 'startDate', sort: true, title: '发车日期'},
            {field: 'dispatchNumber', sort: true, title: '运输单号', templet: '#dispatchNumberTpl2', width: 180},
            {field: 'carrierName', sort: true, title: '承运商名称'},
            {field: 'carnumber', sort: true, title: '车牌号'},
            {field: 'driver1', sort: true, title: '司机名称'},
            {field: 'tel1', sort: true, title: '司机联系方式'},
            {field: 'privatecarType', sort: true, title: '车辆类型'},
            {field: 'mileageTraveled', sort: true, title: '行驶里程'},
            {field: 'totalVolume', sort: true, title: '总体积'},
            {field: 'totalPieces', sort: true, title: '总件数'},
            {field: 'pieceNumberSum', sort: true, title: '整件拆零和'},
            {field: 'freightMoney', sort: true, title: '总运费'},
            {field: 'consultMoney', sort: true, title: '参考运费'},
            {field: 'loadingMoney', sort: true, title: '装车费'},
            {field: 'unloadingMoney', sort: true, title: '卸车费'},
            {field: 'notes', sort: true, title: '备注原因'},
        ]];
    };

    // 渲染表格
    var tableResult2 = table.render({
        elem: '#' + transportConfirm.tableId,
        url: Feng.ctxPath + '/transportCarrierFreight/list2',
        page: true,
        limit: 20,
        height: "full-60",
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        cols: transportConfirm.initColumn(),
        done: function(res, curr, count) {
            var confirmCountElement = $('#confirmCount');

            if (count > 0) {
                // 如果有数据，则设置 <span> 标签的内容
                if (confirmCountElement.length) {
                    confirmCountElement.text(count > 99 ? '99+' : count);
                }
            } else {
                if (confirmCountElement.length) {
                    confirmCountElement.remove();
                }
            }
        }
    });

    /**
     * 财务确定
     * @param data
     */
    transportConfirm.Reconfirm = function (data) {
        // 弹出输入框让用户输入审核意见或备注
        layer.prompt({
            title: '请输入确定意见或备注',
            formType: 2,
            value: '', // 设置默认值为空
            maxlength: 100
        }, function (value, index, elem) {

            var confirmData = {
                id: data.id,
                operateId: data.operateId,
                operateName: data.operateName,
                dispatchNumber: data.dispatchNumber,
                notes: value
            }

            var ajax = new $ax(Feng.ctxPath + "/rec/carrierRecDetail/Reconfirm", function (data) {
                Feng.success("确认成功!");
                table.reload(transportConfirm.tableId);
            }, function (data) {
                Feng.error("确认失败!" + data.responseJSON.message + "!");
            });

            ajax.setData(confirmData);
            ajax.start();
            layer.close(index);
        })

    };

    /**
     * 点击查询按钮
     */
    transportConfirm.search2 = function () {
        var queryData = {};
        queryData['condition'] = $("#condition2").val();
        queryData['operateId'] = $("#operateId2").val();
        queryData['carrierId'] = $("#carrierId2").val();
        table.reload(transportConfirm.tableId, {
            where: queryData, page: {curr: 1},
            done: function () {
                // 搜索按钮点击事件
                $('#btnSearch2').click(function () {
                    transportConfirm.search2();
                });
                // 导出excel
                $('#btnExp2').click(function () {
                    transportConfirm.exportExcel2();
                });
            }
        });
    };

    /**
     * 导出excel按钮
     */
    transportConfirm.exportExcel2 = function () {
        var checkRows = table.checkStatus(transportConfirm.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 财务批量确认
    transportConfirm.btnReconfirm = function () {
        var checkStatus = table.checkStatus(transportConfirm.tableId);
        data = checkStatus.data;

        if (data.length > 0) {
            var ids = [];
            for (var i = 0; i < data.length; i++) {
                ids.push(data[i].id);
            }
            layer.prompt({
                title: '请输入确认意见或备注',
                formType: 2,
                value: '',
                maxlength: 100
            }, function (value, index, elem) {
                $.ajax({
                    url: Feng.ctxPath + "/rec/carrierRecDetail/btnReconfirm?ids=" + ids + "&value=" + value,
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        layer.msg(data.message);
                        table.reload(transportConfirm.tableId);
                    },
                    error: function (jqXHR, textStatus, errorThrown){
                        console.log(errorThrown);
                        layer.msg(data.message);
                    }
                })
                layer.close(index);
            })
        } else {
            layer.alert('请至少选中一条数据');
        }
    };

    // 搜索按钮点击事件
    $('#btnSearch2').click(function () {
        transportConfirm.search2();
    });

    // 导出excel
    $('#btnExp2').click(function () {
        transportConfirm.exportExcel2();
    });

    // 财务批量确认
    $('#btnReconfirm').click(function () {
        transportConfirm.btnReconfirm();
    });

    table.on('tool(' + transportConfirm.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'Reconfirm') {
            // 财务确认
            transportConfirm.Reconfirm(data);
        } else if (layEvent === 'tooTimeLine2') {
            layer.open({
                type: 2,
                title: '时序图',
                area: ['550px', '570px'],
                anim: 5,
                content: Feng.ctxPath + '/rec/carrierRecDetail/tooTimeLine?dispatchNumber=' + data.dispatchNumber,
            });
        } else if (layEvent === 'retract') {
            // 财务撤回
            TransportCarrierFreight.retract(data);
        }
    });

    /**
     * 承运商运费信息表管理
     */
    var transportReConfirm = {
        tableId: "transportReConfirm"
    };

    /**
     * 初始化表格的列
     */
    transportReConfirm.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键id'},
            {align: 'center', toolbar: '#tableBar3', title: '操作', width: 140},
            {field: 'recStatus', sort: true, title: '流程状态', templet: '#recStateTpl'},
            {field: 'operateName', sort: true, title: '项目名称'},
            {field: 'startDate', sort: true, title: '发车日期'},
            {field: 'dispatchNumber', sort: true, title: '运输单号', templet: '#dispatchNumberTpl3', width: 180},
            {field: 'carrierName', sort: true, title: '承运商名称'},
            {field: 'carnumber', sort: true, title: '车牌号'},
            {field: 'driver1', sort: true, title: '司机名称'},
            {field: 'tel1', sort: true, title: '司机联系方式'},
            {field: 'privatecarType', sort: true, title: '车辆类型'},
            {field: 'mileageTraveled', sort: true, title: '行驶里程'},
            {field: 'totalVolume', sort: true, title: '总体积'},
            {field: 'totalPieces', sort: true, title: '总件数'},
            {field: 'pieceNumberSum', sort: true, title: '整件拆零和'},
            {field: 'freightMoney', sort: true, title: '总运费'},
            {field: 'consultMoney', sort: true, title: '参考运费'},
            {field: 'loadingMoney', sort: true, title: '装车费'},
            {field: 'unloadingMoney', sort: true, title: '卸车费'},
            {field: 'notes', sort: true, title: '备注原因'},
        ]];
    };

    // 渲染表格
    var tableResult3 = table.render({
        elem: '#' + transportReConfirm.tableId,
        url: Feng.ctxPath + '/transportCarrierFreight/list3',
        page: true,
        limit: 20,
        height: "full-60",
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        cols: transportReConfirm.initColumn()
    });


    /**
     * 点击查询按钮
     */
    transportReConfirm.search3 = function () {
        var queryData = {};
        queryData['condition'] = $("#condition3").val();
        queryData['operateId'] = $("#operateId3").val();
        queryData['carrierId'] = $("#carrierId3").val();
        table.reload(transportReConfirm.tableId, {
            where: queryData, page: {curr: 1},
            done: function () {
                // 搜索按钮点击事件
                $('#btnSearch3').click(function () {
                    transportReConfirm.search3();
                });
                // 导出excel
                $('#btnExp3').click(function () {
                    transportReConfirm.exportExcel3();
                });
            }
        });
    };

    /**
     * 导出excel按钮
     */
    transportReConfirm.exportExcel3 = function () {
        var checkRows = table.checkStatus(transportReConfirm.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 搜索按钮点击事件
    $('#btnSearch3').click(function () {
        transportReConfirm.search3();
    });

    // 导出excel
    $('#btnExp3').click(function () {
        transportReConfirm.exportExcel3();
    });

    // 生成应付单
    transportReConfirm.generate = function (data) {
        console.log("generate")
    };

    table.on('tool(' + transportReConfirm.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'tooTimeLine3') {
            layer.open({
                type: 2,
                title: '时序图',
                area: ['550px', '570px'],
                anim: 5,
                content: Feng.ctxPath + '/rec/carrierRecDetail/tooTimeLine?dispatchNumber=' + data.dispatchNumber,
            });
        } else if (layEvent === 'generate') {
            transportReConfirm.generate(data);
        }
    });

    /**
     * 承运商运费信息表管理
     */
    var transportComplaint = {
        tableId: "transportComplaint"
    };

    /**
     * 初始化表格的列
     */
    transportComplaint.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键id'},
            {align: 'center', toolbar: '#tableBar4', title: '操作',width: 140},
            {field: 'notes', minwidth: 120, sort: true, title: '备注原因', templet: '#notes'},
            {field: 'recStatus', sort: true, title: '流程状态', templet: '#recStateTpl'},
            {field: 'operateName', sort: true, title: '项目名称'},
            {field: 'startDate', sort: true, title: '发车日期'},
            {field: 'dispatchNumber', sort: true, title: '运输单号', templet: '#dispatchNumberTpl4', width: 180},
            {field: 'carrierName', sort: true, title: '承运商名称'},
            {field: 'carnumber', sort: true, title: '车牌号'},
            {field: 'driver1', sort: true, title: '司机名称'},
            {field: 'tel1', sort: true, title: '司机联系方式'},
            {field: 'privatecarType', sort: true, title: '车辆类型'},
            {field: 'mileageTraveled', sort: true, title: '行驶里程'},
            {field: 'totalVolume', sort: true, title: '总体积'},
            {field: 'totalPieces', sort: true, title: '总件数'},
            {field: 'pieceNumberSum', sort: true, title: '整件拆零和'},
            {field: 'freightMoney', sort: true, title: '总运费'},
            {field: 'consultMoney', sort: true, title: '参考运费'},
            {field: 'loadingMoney', sort: true, title: '装车费'},
            {field: 'unloadingMoney', sort: true, title: '卸车费'},
        ]];
    };

    // 渲染表格
    var tableResult4 = table.render({
        elem: '#' + transportComplaint.tableId,
        url: Feng.ctxPath + '/transportCarrierFreight/list4',
        page: true,
        limit: 20,
        height: "full-60",
        toolbar: '#toolbarfrom',
        lineStyle: 'height: 151px;', // 定义表格的多行样式
        cellMinWidth: 100,
        cols: transportComplaint.initColumn(),
        done: function (res, curr, count) {
            var complaintCountElement = $('#complaintCount');

            if (count > 0) {
                // 如果有数据，则设置 <span> 标签的内容
                if (complaintCountElement.length) {
                    complaintCountElement.text(count > 99 ? '99+' : count);
                }
            } else {
                if (complaintCountElement.length) {
                    // complaintCountElement.text(''); // 清空内容
                    complaintCountElement.remove();
                }
            }
        }
    });

    // 承运商撤回
    transportComplaint.carrierRetract = function (data) {
        // 弹出输入框让用户输入审核意见或备注
        layer.prompt({
            title: '请输入撤回原因',
            formType: 2,
            value: '', // 设置默认值为空
            maxlength: 100
        }, function (value, index, elem) {

            var confirmData = {
                id: data.id,
                operateId: data.operateId,
                operateName: data.operateName,
                dispatchNumber: data.dispatchNumber,
                notes: value
            }

            var ajax = new $ax(Feng.ctxPath + "/rec/carrierRecDetail/carrierRetract", function (data) {
                Feng.success("撤回成功!");
                table.reload(transportComplaint.tableId);
            }, function (data) {
                Feng.error("撤回失败!" + data.responseJSON.message + "!");
            });

            ajax.setData(confirmData);
            ajax.start();
            layer.close(index);
        })
    }

    // 财务撤回
    transportComplaint.financeRetract = function (data) {
        // 弹出输入框让用户输入审核意见或备注
        layer.confirm('是否确认已更改？', {icon: 3}, function () {
            var confirmData = {
                id: data.id,
                operateId: data.operateId,
                operateName: data.operateName,
                dispatchNumber: data.dispatchNumber,
                notes: "已更改详细信息"
            }

            var ajax = new $ax(Feng.ctxPath + "/rec/carrierRecDetail/financeRetract", function (data) {
                layer.msg(data.message, {icon: 1});
                table.reload(transportComplaint.tableId);
            }, function (data) {
                Feng.error("撤回失败!" + data.message + "!");
            });

            ajax.setData(confirmData);
            ajax.start();
        }, function () {
            layer.msg('已取消');
        });
    };

    /**
     * 点击查询按钮
     */
    transportComplaint.search4 = function () {
        var queryData = {};
        queryData['condition'] = $("#condition4").val();
        queryData['operateId'] = $("#operateId4").val();
        queryData['carrierId'] = $("#carrierId4").val();
        table.reload(transportComplaint.tableId, {
            where: queryData, page: {curr: 1},
            done: function () {
                // 搜索按钮点击事件
                $('#btnSearch4').click(function () {
                    transportComplaint.search4();
                });
                // 导出excel
                $('#btnExp4').click(function () {
                    transportComplaint.exportExcel4();
                });
            }
        });
    };

    /**
     * 导出excel按钮
     */
    transportComplaint.exportExcel4 = function () {
        var checkRows = table.checkStatus(transportComplaint.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 搜索按钮点击事件
    $('#btnSearch4').click(function () {
        transportComplaint.search4();
    });

    // 导出excel
    $('#btnExp4').click(function () {
        transportComplaint.exportExcel4();
    });

    table.on('tool(' + transportComplaint.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'tooTimeLine4') {
            layer.open({
                type: 2,
                title: '时序图',
                area: ['550px', '570px'],
                anim: 5,
                content: Feng.ctxPath + '/rec/carrierRecDetail/tooTimeLine?dispatchNumber=' + data.dispatchNumber,
            });
        } else if (layEvent === 'carrierRetract') {
            transportComplaint.carrierRetract(data);
        } else if (layEvent === 'financeRetract') {
            transportComplaint.financeRetract(data);
        }
    });
});
